$(() => {
  //配置裁切框
  let option = {
    aspectRatio: 1,
    preview: '.img-preview',
  };
  fileEvent(option);
  //创建裁切框
  image.cropper(option);
  //文件上传后改变裁切框的图片
  $('#sure').click(function () {
    let i = image.cropper('getCroppedCanvas', {
      width: 100,
      height: 100,
    });
    let base64 = i.toDataURL();
    $.ajax({
      type: 'POST',
      url: '/my/update/avatar',
      data: {
        avatar: base64,
      },
      success(res) {
        image.cropper('disable');
        $('#file')[0].disabled = true;
        $('#chooseImage')[0].disabled = true;
        $('#sure')[0].disabled = true;
        layer.msg(res.message, function () {
          if (res.status === 0) {
            window.parent.getUserInfo();
            layer.msg('60秒之后,可以重新上传,请稍后');
            setTimeout(function () {
              image.cropper('enable');
              $('#file')[0].disabled = false;
              $('#chooseImage')[0].disabled = false;
              $('#sure')[0].disabled = false;
            }, 60000);
          }
        });
      },
    });
  });
});
